
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.GoodsRecommend;
import com.shop.cloud.mall.admin.service.GoodsRecommendService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 商品推荐
 *
 * @author
 * @date 2023-10-16 10:25:37
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/goodsrecommend")
@Tag(description = "goodsrecommend", name = "商品推荐管理")
public class GoodsRecommendController {

    private final GoodsRecommendService goodsRecommendService;

    /**
     * 商品推荐分页列表
     * @param page 分页对象
     * @param goodsRecommend 商品推荐
     * @return
     */
    @Operation(summary = "商品推荐分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:goodsrecommend:index')")
    public R getPage(Page page, GoodsRecommend goodsRecommend) {
        return R.ok(goodsRecommendService.page(page, Wrappers.query(goodsRecommend)));
    }

    /**
     * 商品推荐查询
     * @param id
     * @return R
     */
    @Operation(summary = "商品推荐查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:goodsrecommend:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(goodsRecommendService.getById(id));
    }

    /**
     * 商品推荐新增
     * @param goodsRecommend 商品推荐
     * @return R
     */
    @Operation(summary = "商品推荐新增")
    @SysLog("新增商品推荐")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:goodsrecommend:add')")
    public R save(@RequestBody GoodsRecommend goodsRecommend) {
        return R.ok(goodsRecommendService.save(goodsRecommend));
    }

    /**
     * 商品推荐修改
     * @param goodsRecommend 商品推荐
     * @return R
     */
    @Operation(summary = "商品推荐修改")
    @SysLog("修改商品推荐")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:goodsrecommend:edit')")
    public R updateById(@RequestBody GoodsRecommend goodsRecommend) {
        return R.ok(goodsRecommendService.updateById(goodsRecommend));
    }

    /**
     * 商品推荐删除
     * @param id
     * @return R
     */
    @Operation(summary = "商品推荐删除")
    @SysLog("删除商品推荐")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:goodsrecommend:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(goodsRecommendService.removeById(id));
    }

}
